using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Data.Database;
using Dimok.GLRules;
using Dimok.User;

namespace Dimok.GLRules{
	public partial class EditCondition : System.Web.UI.Page{
		protected HtmlSelect selFieldUnit;
		protected Literal ltrFields;
		protected Literal ltrXml;

		private void Page_Load(object sender, System.EventArgs e){
			Response.Cache.SetCacheability(HttpCacheability.NoCache);
			UserObject uox = new UserObject();
			string ruleID = UserObject.GetQueryParam("RuleID");
			int programID = int.Parse(UserObject.GetQueryParam("ProgramID"));
			ColumnPropertiesDS dsCP = new ColumnPropertiesDS();
			SQLHelperEx.ExecuteDatasetEx(uox.db_GL,dsCP.t_ColumnProperties,
				@"SELECT CP.ID, ISNULL(CP.Lable,FieldName) AS Lable, ISNULL(CP.Description,'') AS Description,
								 CP.Units, ISNULL(CP.RejectMessage,'') AS RejectMessage
					FROM t_GLRules GLR INNER JOIN t_ColumnProperties CP ON GLR.ColumnID = CP.ID WHERE (GLR.ID = @RuleID)",ruleID);
			if( dsCP.t_ColumnProperties.Rows.Count == 0 ){
				ColumnPropertiesDS.t_ColumnPropertiesDataTable dtCP = dsCP.t_ColumnProperties;
				dtCP.Addt_ColumnPropertiesRow("","","","");
				dtCP.AcceptChanges();
			}
			dsCP.Namespace = null;
			ltrXml.Text = dsCP.GetXml();
			selFieldUnit.DataSource = SQLHelperEx.ExecuteDatasetEx(uox.db_GL,"SELECT Units FROM t_GL_Unit");
			selFieldUnit.DataTextField = "Units";
			selFieldUnit.DataValueField = "Units";
			selFieldUnit.DataBind();
			ltrFields.Text = (new WS()).FieldsList(programID,true,"ColumnName");
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e) {
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}